package org.luxor.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.luxor.commons.core.utils.BeanUtils;
import org.luxor.system.entity.SysUserRoleRefEntity;
import org.luxor.system.mapper.SysUserRoleRefMapper;
import org.luxor.system.service.ISysUserRoleRefService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;

/**
 * 角色与角色对应关系
 *
 * @author Mark @date 2020-07-26 16:52:22
 */
@Service("sysUserRoleRefService")
public class SysUserRoleRefServiceImpl extends ServiceImpl<SysUserRoleRefMapper, SysUserRoleRefEntity> implements ISysUserRoleRefService {

    @Override
    public IPage<SysUserRoleRefEntity> page(IPage<SysUserRoleRefEntity> page, Map query) {
        SysUserRoleRefEntity queryEntity = BeanUtils.toObject(SysUserRoleRefEntity.class, query);
        return super.page(page, Wrappers.query(queryEntity));
    }

    @Override
    public Collection<SysUserRoleRefEntity> listByUserId(Long userId) {
        Wrapper<SysUserRoleRefEntity> queryWrapper = Wrappers.<SysUserRoleRefEntity>lambdaQuery()
                .eq(SysUserRoleRefEntity::getUserId, userId);
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public Collection<SysUserRoleRefEntity> listByRoleId(Long roleId) {
        Wrapper<SysUserRoleRefEntity> queryWrapper = Wrappers.<SysUserRoleRefEntity>lambdaQuery()
                .eq(SysUserRoleRefEntity::getRoleId, roleId);
        return getBaseMapper().selectList(queryWrapper);
    }
}
